#include "gtest/gtest.h"

#include "../src/sort/sort.h"

#define ARR_SIZE 20

using namespace csz;

TEST(SortTest, BubbleSort)
{
	SortFamily *sortFamily = new SortFamily();

	Array<int> *randArr = Array<int>::GetRandArr(ARR_SIZE, 100);
	//复制一份随机数组并用冒泡排序进行排序作为基准
	Array<int> *stdArr = randArr->copy();
	sortFamily->BubbleSort(stdArr->getArray(), stdArr->getSize());

	sortFamily->QuickSort(randArr->getArray(), 0, randArr->getSize() - 1);
	ASSERT_TRUE(randArr->equal(stdArr));

	randArr->shuffle();
	sortFamily->HeapSort(randArr->getArray(), randArr->getSize());
	ASSERT_TRUE(randArr->equal(stdArr));

	randArr->shuffle();
	sortFamily->InsSort(randArr->getArray(), randArr->getSize());
	ASSERT_TRUE(randArr->equal(stdArr));

	randArr->shuffle();
	int* tmpArr = new int[randArr->getSize()];
	sortFamily->MergeSort(randArr->getArray(), 0, randArr->getSize() - 1, tmpArr);
	ASSERT_TRUE(randArr->equal(stdArr));

	randArr->shuffle();
	sortFamily->SelSort(randArr->getArray(), randArr->getSize());
	ASSERT_TRUE(randArr->equal(stdArr));

	randArr->shuffle();
	sortFamily->ShellSort(randArr->getArray(), randArr->getSize());
	ASSERT_TRUE(randArr->equal(stdArr));

	delete randArr;
	delete stdArr;
	delete tmpArr;
}